Skip to content

gh-146065: Fix NULL dereference in FutureIter_am_send#146304

Open
VanshAgarwal24036 wants to merge 5 commits intopython:mainfrom
VanshAgarwal24036:gh-146065-fix-futureiter-null-deref
Open

gh-146065: Fix NULL dereference in FutureIter_am_send#146304
VanshAgarwal24036 wants to merge 5 commits intopython:mainfrom
VanshAgarwal24036:gh-146065-fix-futureiter-null-deref

Conversation

@VanshAgarwal24036
Copy link
Contributor

@VanshAgarwal24036 VanshAgarwal24036 commented Mar 22, 2026

After throw() or close(), it->future can be NULL. A subsequent send() call would dereference it and crash. This adds a NULL check and raises StopIteration instead.

@bedevere-app
Copy link

bedevere-app bot commented Mar 22, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@VanshAgarwal24036
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Mar 22, 2026

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 22, 2026 19:04
@JesusAnaya
Copy link

I was able to reproduce and verify this fix locally on macOS (x86_64), CPython debug build (./configure --with-pydebug && make -j8).

Without the fix (NULL check in FutureIter_am_send removed): test_futureiter_send_after_throw_no_crash crashes with a segfault, confirmed NULL dereference in FutureIter_am_send when it->future is NULL after a prior throw().

With the fix (NULL check restored): all three variants of the test pass (CFutureTests, CSubFutureTests, PyFutureTests), and the full test.test_asyncio.test_futures suite passes (186/186 tests OK, no regressions).

The fix is minimal and correct, it mirrors the existing guard pattern used elsewhere in the future iterator code paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants